<%@ page import="java.sql.*"
%><%@ page import="kr.sdworld.wedding.WeddingComment"
%><%@ page import="java.text.SimpleDateFormat"
%><%@ page import="java.util.*"
%><%@ page import="java.util.Date"
%>
<%@ page import="kr.sdworld.wedding.WeddingCommentReply" %>
<%!
    public static Connection getConnection() throws Exception {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@ora-003.cafe24.com:1521:orcl", "miru032", "my1004sd");

        return conn;
    }
%><%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");

    List<WeddingComment> resultList = new ArrayList<WeddingComment>();
    try
    {
        Connection conn = getConnection();

        StringBuilder sbQuery = new StringBuilder();
        sbQuery.append("SELECT * FROM WEDDING_COMMENT ORDER BY REG_DT");

        PreparedStatement pstmt = conn.prepareStatement(sbQuery.toString());
        ResultSet rs = pstmt.executeQuery();

        while(rs.next()) {
            WeddingComment weddingComment = new WeddingComment();
            weddingComment.setObjId(rs.getLong("OBJ_ID"));
            weddingComment.setCommentId(rs.getString("COMMENT_ID"));
            weddingComment.setCommentText(rs.getString("COMMENT_TEXT"));
            weddingComment.setUserIp(rs.getString("USER_IP"));
            weddingComment.setRegDt(rs.getTimestamp("REG_DT"));

            resultList.add(weddingComment);
        }

        rs.close();
        pstmt.close();
        conn.close();
    }
    catch(Exception e) {
        e.printStackTrace();
    }
%><%
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd HH:mm:ss");
    for(WeddingComment weddingComment:resultList) {
        Date date = new Date(weddingComment.getRegDt().getTime());
        String regDt = sdf.format(date);

        Long objId = weddingComment.getObjId();
        Connection conn = getConnection();
        PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM WEDDING_COMMENT_REPLY WHERE COMMENT_ID = ?");
        pstmt.setLong(1, objId);
        ResultSet rs = pstmt.executeQuery();
        WeddingCommentReply reply = null;
        if(rs.next()) {
            reply = new WeddingCommentReply();
            reply.setObjId(rs.getLong("OBJ_ID"));
            reply.setReplyId(rs.getString("REPLY_ID"));
            reply.setReplyText(rs.getString("REPLY_TEXT"));
            reply.setUserIp(rs.getString("USER_IP"));
            reply.setRegDt(rs.getTimestamp("REG_DT"));
            reply.setCommentId(rs.getLong("COMMENT_ID"));
        }

        rs.close();
        pstmt.close();
        conn.close();%>
        <tr>
            <td class='commentId nanum-g'><%=weddingComment.getCommentId()%></td>
            <td class='commentText nanum-g'>
                <span class='text'><%=weddingComment.getCommentText()%></span>
                <span class='delete text'>&nbsp;<img src='resources/images/delete.png' style='width:24px;' valign='middle' /></span>
                <input type='hidden' name='objId' value='<%=weddingComment.getObjId()%>' />
                <span class='deletePannel'>
                    <span><img src='resources/images/forward.png' border='0' style='width:24px;' valign='middle'/></span>
                    <span> PW : <input type='password' name='commentPw' style='width:100px;padding:5px;font-size:17px;'/></span>
                    <span class='item submitDelete'><img src='resources/images/submit.png' style='width:24px;' valign='middle' /></span>
                    <span class='item submitCancel'><img src='resources/images/back.png' style='width:32px;' valign='middle' /></span>
                </span>
            </td>
            <td class='regDt nanum-g'><%=regDt%></td>
        </tr><%
        if(reply != null) {%>
            <tr>
                <td class='commentId nanum-g'><%=reply.getReplyId()%></td>
                <td class='commentText nanum-g' style="padding-left: 20px;"><img src="resources/images/reply.png" style="width:24px;" valign="middle" /> <%=reply.getReplyText()%></td>
                <td class='regDt nanum-g'><%=sdf.format(reply.getRegDt())%></td>
            </tr><%
        }
    }%>



